/**
 * 文件下载
 * @param filePath {string} 文件下载路径
 * @param fileName {string} [fileName=''] 文件名称
 */
export function download (filePath, fileName = '') {
  this.$http.get(filePath, {}, {
    responseType: 'blob'
  }).then(res => {
    if (res) {
      if ('msSaveBlob' in navigator) { // 对IE和Edge的兼容
        window.navigator.msSaveBlob(res, fileName)
      } else {
        let blob = res
        let a = document.createElement('a')
        let url = window.URL.createObjectURL(blob)
        let evt = document.createEvent('HTMLEvents') // 对firefox的兼容
        evt.initEvent('click', false, false) // 对firefox的兼容
        a.style.display = 'none'
        a.href = url
        a.download = fileName
        a.dispatchEvent(evt) // 对firefox的兼容
        a.click()
        window.URL.revokeObjectURL(url)
      }
    }
  })
}
